﻿function AddPlayer(name) {
    $.ajax
    ({
        type: 'POST',
        dataType: 'json',
        url: "../GameServices.svc/players/addNewPlayer/",
        contentType: "application/json; charset=utf-8",
        data: '{"playerName":"' + name + '"}',
        success: function (json) { console.debug(json); },
        error: function (xhr, ajaxOptions, thrownError) { }
    });
}

function DeletePlayer(playerId) {
    $.ajax
    ({
        type: 'POST',
        dataType: 'json',
        url: "../GameServices.svc/players/deletePlayer/",
        contentType: "application/json; charset=utf-8",
        data: '{"playerId":"' + playerId + '"}',
        success: function (msg) { },
        error: function (xhr, ajaxOptions, thrownError) { }
    });
}

function AddPendingGame(playerId) {
    $.ajax
    ({
        type: 'POST',
        dataType: 'json',
        url: "../GameServices.svc/games/addPendingGame/",
        contentType: "application/json; charset=utf-8",
        data: '{"playerId":"' + playerId + '"}',
        success: function (json) { console.debug(json); },
        error: function (xhr, ajaxOptions, thrownError) { }
    });
}

function GetAllPendingGames() {
    $.ajax
    ({
        type: 'GET',
        dataType: 'json',
        url: "../GameServices.svc/games/getAllPendingGames/",
        success: function (json) { console.debug(json); },
        error: function (xhr, ajaxOptions, thrownError) { }
    });
}

function JoinGame(pendingGame) {
    var jsonStr = JSON.stringify(pendingGame);
    $.ajax
    ({
        type: 'POST',
        dataType: 'json',
        url: "../GameServices.svc/games/joinGame/",
        contentType: "application/json; charset=utf-8",
        data: jsonStr,
        success: function (json) { console.debug(json); },
        error: function (xhr, ajaxOptions, thrownError) { }
    });
}